package com.zkingsoft.actions.api;

import java.util.Arrays;
import java.util.List;

import org.apache.tools.ant.types.resources.selectors.Date;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sun.tools.internal.xjc.generator.bean.ImplStructureStrategy.Result;
import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.plugin.util.DateUtils;
import com.zkingsoft.pojo.AjaxResult;

/**
 * 
* @Description: 不需要登录可以访问的action
* @author:姜友瑶 
* @date 2016年8月31日
 */
@RequestMapping(value = "/api")
@Controller
public class Api extends BaseController {

	/**
	 * 
	 * @Description: 页面定向方法，每个权限模块公用一个，每个模块共享一个一级路径，已便于进行权限过滤
	 * @author:姜友瑶
	 * @param page1
	 * @param page2
	 * @return 返回类型 String
	 * @date 2016年8月31日
	 */
	@RequestMapping(value = "/redirect/{page1}/{page2}")
	public String redirect(@PathVariable("page1") String page1, @PathVariable("page2") String page2) {
		return "api/" + page1 + "/" + page2;
	}

	@RequestMapping(value = "/redirect/{page1}")
	public String redirect(@PathVariable("page1") String page1) {
		return "api/" + page1;
	}
	
	@RequestMapping(value = "/findFruits")
	public @ResponseBody AjaxResult findFruits(String kinds) {
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		List<Fruits> fruits=Arrays.asList(
				new Fruits("香蕉", "50","/matrix-web/resource/images/xj.jpg"), 
				new Fruits("苹果", "30","/matrix-web/resource/images/pg.jpg"),
				new Fruits("梨子", "20","/matrix-web/resource/images/lz.jpg") );
		
		AjaxResult result = new AjaxResult(AjaxResult.STATUS_OK, null, null, fruits, fruits.size());
		result.putInMap("time", DateUtils.getTimeMark());
		return result;
	}
	
}


class Fruits{
	String name;
	String price;
	String img;
	
	
	
	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}

	public Fruits(String name,String price,String img) {
		this.name=name;
		this.price=price;
		this.img=img;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPrice() {
		return price;
	}
	public void setPrice(String price) {
		this.price = price;
	}
}
